/**
 * ObjectHelper
 *
 * Released under Apache License, Version 2.0.
 */

package bsp.helper.objects;

import bsp.helper.StringHelper;

public class ObjectHelper
{
	protected ObjectHelper()
	{
		/* empty by design */
	}
	
	public static Pair<String, String> makeStringPair(String src, char separator)
	{
		Pair<String, String> sp = new Pair<String, String>();
		int idx;
		
		if ( src != null ) {
			// remove all extra spaces
			src = StringHelper.trim(src);
			// get first occurrence of separator char
			idx = src.indexOf(separator);
			if ( idx != -1 ) {
				if ( idx == (src.length() - 1) ) {
					sp.one = StringHelper.trim(StringHelper.freshSubstring(src, 0, idx));;
					sp.two = null;
				} else {
					sp.one = StringHelper.trim(StringHelper.freshSubstring(src, 0, idx));
					sp.two = StringHelper.trim(StringHelper.freshSubstring(src, idx + 1, src.length()));
				}
			} else {
				sp.one = src;
				sp.two = null;
			}
		}
		
		return sp;
	}
	
	public static Pair<String, String> makeStringPair(String src, String separator)
	{
		Pair<String, String> sp = new Pair<String, String>();
		int idx;
		
		if ( src != null ) {
			// remove all extra spaces
			src = StringHelper.trim(src);
			// get first occurrence of separator char
			idx = src.indexOf(separator);
			if ( idx != -1 ) {
				if ( idx == (src.length() - separator.length()) ) {
					sp.one = StringHelper.trim(StringHelper.freshSubstring(src, 0, idx));;
					sp.two = null;
				} else {
					sp.one = StringHelper.trim(StringHelper.freshSubstring(src, 0, idx));
					sp.two = StringHelper.trim(StringHelper.freshSubstring(src, idx + separator.length() + 1, src.length()));
				}
			} else {
				sp.one = src;
				sp.two = null;
			}
		}
		
		return sp;
	}
}

/* end */
